package com.gca.airhockey;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.shape.Shape;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsConnector;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.util.MathUtils;

import android.os.Bundle;
import android.os.CountDownTimer;

import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;

import java.util.Random;

import android.content.Context;

public class PowerUp {
	// ===========================================================
	// Constants
	// ===========================================================
	private static final String POWERUP_IMAGE = "gfx/beer_powerUp.png";

	private int POS_X = 50;
	private int POS_Y = 50;

	private BitmapTextureAtlas mTexture;
	private TextureRegion mRegion;
	private Body mBody;
	private Sprite mSprite;

	// ===========================================================
	// Constructors
	// ===========================================================
	public PowerUp(Context pContext, Engine engine,PhysicsWorld physicsWorld) {
		
		this.mTexture = new BitmapTextureAtlas(256, 256,
				TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.mRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mTexture, 
				pContext, POWERUP_IMAGE, 0, 0);
		engine.getTextureManager().loadTexture(this.mTexture);
		
		setPowerUpToRandomCell(1280, 752);
		this.mSprite = new Sprite(POS_X, POS_Y, mRegion);
		
		this.mSprite.setScale(0.3f);
		//final FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(1, 2f, 0);
		
		
		//mBody = PhysicsFactory.createBoxBody(physicsWorld, mSprite, BodyType.StaticBody, objectFixtureDef);
		//mBody.setFixedRotation(true);
	}
	
	
	// ===========================================================
	// Getters and Setters
	// ===========================================================
	public void setPowerUpToRandomCell(int width, int depth) {
        this.setPos(MathUtils.random(1, width - 20), MathUtils.random(1, depth - 20));
	}
	public void setPos(int x, int y){
		POS_X = x;
		POS_Y = y;
	}
	
	
	public Sprite getSprite() {
		return mSprite;
	}
	public Body getBody() {
		return mBody;
	}
	
}
